<?php

namespace App\Http\Controllers\Admin\Shop;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Admin\CommonController;
use App\Models\shop\Express;

class ExpressController extends CommonController
{
    public function __construct()
    {
        parent::__construct();
        view()->share([
            '_system' => 'shop',
            '_express' => 'am-active',
            '_shop' => 'am-in',
        ]);
    }

    //显示首页
    public function index(Request $request)
    {
        $expresses=Express::get();
//        return $expresses;
        return view('admin.shop.expresses.index')->with('expresses',$expresses);
    }

    //显示创建
    public function create()
    {
        return view('admin.shop.expresses.create');
    }
    //存储
    public function store(Request $request)
    {
//        return $request->all();
        Express::create($request->all());
        return redirect(route('shop.express.index'))->with('express','新增快递成功~');
    }

    //显示编辑
    public function edit($id)
    {
        $express=Express::find($id);
//        return $express;
        return view('admin.shop.expresses.edit')->with('express',$express);

    }

    //更新
    public function update(Request $request,$id)
    {
        $express=Express::find($id);
        $express->update($request->all());  //修改request上提交的所有数据
        return redirect(route('shop.express.index'))->with('express','编辑快递成功~');

    }

    //删除
    public function destroy($id)
    {
        Express::destroy($id);
        return redirect(route('shop.express.index'))->with('express','删除快递成功~');
    }






    //切换是否可用
    public function is_enable(Request $request)
    {
        $id=$request->id;
        $express=Express::find($id);
        $express->is_enable=$express->is_enable?false:true;
        $express->save();
    }

    //排序
    public function sort_order(Request $request)
    {
        $id=$request->id;
        $sort_order=$request->sort_order;
        $express=Express::find($id);
        $express->sort_order=$sort_order;
        $express->save();
    }

}
